/*
 * $Id$
 */
package py.windmill.util;

import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 *
 * @author myang
 */
public abstract class StreamReader<T> {

    /**
     * 
     * @param input
     * @return 
     */
    public T readThenClose(final InputStream input) {
        try {
            try {
                return read(input instanceof 
                  BufferedInputStream ? input : new BufferedInputStream(input));
            } 
            finally {
                input.close();
            }
        } 
        catch (final Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    /**
     * 
     * @param input
     * @return 
     */
    public abstract T read(InputStream input) throws Exception;
}
